import { reactive, ref } from 'vue';
import { defineStore } from 'pinia';
import { IsEmpty } from '@/utils/common';

export const WebSocketStores = defineStore('WebSocketStores', () => {
  let currentDate = reactive({}) as any; /**服务器当前时间 */
  let currentMaininfo = reactive({ maininfoId: '', rptGroup: '', sampleNo: '', sampleda: '', reqNo: '' }) as any; /**当前已出结果的标本号 */
  let isChangeDate = ref(false); /**跨天是否切换当天 */

  /**
   * 设置当前日期
   * @param arr
   */
  function setCurrentDate(val: any) {
    if (IsEmpty(val)) {
      currentDate = null;
      localStorage.setItem('currentDate', '');
    } else {
      Object.assign(currentDate, val);
      localStorage.setItem('currentDate', val.currentDate);
    }
  }

  /**
   * 设置当前已出结果标本号
   * @param arr
   */
  function setCurrentMaininfo(val: any) {
    if (IsEmpty(val)) {
      Object.assign(currentMaininfo, { maininfoId: '', rptGroup: '', sampleNo: '', sampleda: '', reqNo: '' });
    } else {
      Object.assign(currentMaininfo, val);
    }
  }

  /**
   * 设置是否切换当前日期
   * @param arr
   */
  function setIsChangeDate(val: any) {
    if (IsEmpty(val)) {
      isChangeDate.value = false;
    } else {
      isChangeDate.value = val;
    }
  }

  return { currentDate, currentMaininfo, isChangeDate, setCurrentDate, setCurrentMaininfo, setIsChangeDate };
});
